package com.example.shopping.authority.controller;

import com.example.shopping.JsonResult;
import com.example.shopping.authority.entity.Cart;
import com.example.shopping.authority.entity.Shipping;
import com.example.shopping.authority.mapper.CartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/Cart")
public class CartController {

    @Autowired
    CartMapper cartMapper;

    @GetMapping("/find")
    //查询购物车所有商品
    public JsonResult getCartList(int userid) {
        List<Cart> goods =  cartMapper.getCartList(userid);
        return new JsonResult(true, "查询成功", goods);
    }

    @PostMapping("/update")
    //修改购物车商品   参数(数量，状态，id)
    public JsonResult getCartUpdate(int quantity,int checked,int id) {
        int goods =  cartMapper.getCartUpdate(quantity,checked,id);
        return new JsonResult(true, "查询成功", goods);
    }

    @GetMapping("/del")
    //删除一个购物车商品
    public JsonResult getCartDel(int id) {
        int goods =  cartMapper.getCartDel(id);
        return new JsonResult(true, "查询成功", goods);
    }

    @PostMapping("/addorders")
    //添加一个订单    参数(用户id,商品id,商品数量,运费,实付金额,订单状态,付款类型)
    public JsonResult getCartAddOrders(int userid,int productid,int quantity,int postage,int payment,int status,int paymenttype) {
        int goods =  cartMapper.getCartAddOrders(userid,productid,quantity,postage,payment,status,paymenttype);
        return new JsonResult(true, "添加成功", goods);
    }

    @GetMapping("/alldel")
    //清空购物车所有商品
    public JsonResult getCartAllDel() {
        int goods =  cartMapper.getCartAllDel();
        return new JsonResult(true, "删除成功", goods);
    }

    @GetMapping("/shippingfind")
    //查找默认地址
    public JsonResult getCartShipping(int userid,int id) {
        List<Shipping> goods =  cartMapper.getCartShipping(userid,id);
        return new JsonResult(true, "查询成功", goods);
    }

}
